
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

package com.hlkj.pay.controller.admin;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.pay.app.adminuser.IAdminUserLoginAppService;
import com.hlkj.pay.app.common.IAuthCodeService;
import com.hlkj.pay.vo.admin.req.user.AdminAuthCodeReq;
import com.hlkj.pay.vo.admin.req.user.AdminUserForgetPwdReq;
import com.hlkj.pay.vo.admin.req.user.AdminUserLoginReq;
import com.hlkj.pay.vo.admin.req.user.AdminUserPhoneLoginReq;
import com.hlkj.pay.vo.common.resp.token.LoginTokenResp;
import com.hlkj.pay.vo.common.resp.token.OauthTokenResp;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author HlpayTeam
 * @date 2024/09/10 11:02
 */
@Tag(name = "登录认证")
@RestController
@RequestMapping("/v1/auth/user")
@RequiredArgsConstructor
public class AdminAuthController {

    private final IAdminUserLoginAppService adminUserService;
    private final IAuthCodeService authCodeService;

    @Operation(summary = "账号密码登录")
    @PostMapping("/login")
    @ResponseBody
    CommonResult<LoginTokenResp> login(@Validated @RequestBody AdminUserLoginReq userLoginReq) {
        return adminUserService.login(userLoginReq);
    }
    @Operation(summary = "验证码登录")
    @PostMapping("/codeLogin")
    @ResponseBody
    CommonResult<LoginTokenResp> smsCodeLogin(@Validated @RequestBody AdminUserPhoneLoginReq userLoginReq) {
        return adminUserService.codeLogin(userLoginReq);
    }

    @Operation(summary = "登出")
    @PostMapping("/logout")
    @ResponseBody CommonResult<Void> logout() {
        return adminUserService.logout();
    }

    @Operation(summary = "刷新token")
    @GetMapping("/refreshToken")
    @ResponseBody
    CommonResult<OauthTokenResp> refreshToken(@RequestParam String refreshToken) {
        return adminUserService.refreshToken(refreshToken);
    }

    @Operation(summary = "发送短信验证码")
    @PostMapping("/sendAuthCode")
    @ResponseBody
    CommonResult<Void> sendAuthCode(@Validated @RequestBody AdminAuthCodeReq adminAuthCodeReq) {
        // AdminAuthCodeEnum authCodeEnum = AdminAuthCodeEnum.from(adminAuthCodeReq.getBusinessScenario());
        return authCodeService.sendAuthCode(adminAuthCodeReq);
    }

    @Operation(summary = "多因子登录")
    @GetMapping("/mfaLogin")
    @ResponseBody
    CommonResult<OauthTokenResp> mfaLogin(@RequestParam String authCode) {
        return adminUserService.mfaLogin(authCode);
    }
    
    
    @Operation(summary = "忘记密码")
    @PostMapping("/forgetPwd")
    @ResponseBody
    CommonResult<Void> forgetPwd(@Validated @RequestBody AdminUserForgetPwdReq adminUserForgetPwdReq) {
        return adminUserService.forgetPwd(adminUserForgetPwdReq);
    }

}
